package com.teamwings.ctrls.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public interface CommonMapper {
    @Select("select * from ${tableName} where id = #{tableId}")
    Map<String, Object> getOne(@Param("tableName") String tableName, @Param("tableId") String tableId);

    @Select("select * from ${tableName} where id in (${tableIdsSql})")
    List<Map<String, Object>> getListByIds(@Param("tableName") String tableName, @Param("tableIdsSql") String tableIdsSql);

    @Select("select * from ${tableName} where ${sql}")
    List<Map<String, Object>> getList(@Param("tableName") String tableName, @Param("sql") String sql);

    @Insert("${sql}")
    int insertBySql(@Param("sql") String sql);

    @Update("${sql}")
    int updateBySql(@Param("sql") String sql);

    @Select("select role_code from sys_role where id in (select role_id from sys_user_role where user_id = (select id from sys_user where username=#{username}))")
    List<String> getRoleByUserName(@Param("username") String username);
}
